package com.itheima;

import com.itheima.list.ListNode;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;


public class Topic160 {


    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {

        int flag = 0;
        ListNode result = null;
        List<ListNode> list = new ArrayList<ListNode>();
        while(headA != null) {
            list.add(headA);
            ListNode nextNode = headA.next;
            headA = nextNode;
        }
        while(headB != null) {
            if(list.contains(headB)) {
                flag = 1;
                result = headB;
            }
            ListNode nextNode = headA.next;
            headA = nextNode;
        }
        if(flag == 0) {
            return null;
        } else {
            return result;
        }
    }

    @Test
    public void test() {


    }
}
